﻿using System;
using System.IO;

using Mono.Options;

using octalforty.Componento.Core.ApplicationServices;

namespace octalforty.Componento.Commands
{
    [Command("init")]
    public class InitCommand : ICommand
    {
        internal class Options
        {
            public bool Probe
            { get; set; }
        }

        public MetadirectoryManagerService MetadirectoryManager
        { get; set; }

        public OptionSet GetOptionSet(object options)
        {
            var o = (Options)options;

            return new OptionSet {
                { "p|probe", "Specifies whether to probe directories for \"lib\". Default is \"true\".", probe => o.Probe = probe != null}
            };
        }

        public void Execute(string[] args)
        {
            var options = new Options { Probe = true };

            var rest = GetOptionSet(options).Parse(args);

            var basePath = rest.Count == 0 ?
                Directory.GetCurrentDirectory() :
                rest[0];

            MetadirectoryManager.Initialize(basePath, options.Probe);
        }
    }
}
